﻿<%@ WebHandler Language="C#" Class="WorkOrder" %>

using Activity;
using Activity.API;
using Ext.Net;
using System;

public class WorkOrder : BaseHandler
{
    /// <summary>
    /// 获取店铺信息
    /// </summary>
    /// <param name="shopNames"></param>
    public void GetShopList()
    {
        string shopNames = _httpReuqest["shopNames"];
        int userID = 0;
        int.TryParse(_httpReuqest["userID"], out userID);
        var finishHandler = new WorkOrderHandler();
        var list = finishHandler.GetShopList(shopNames, userID);
        Success(list);
    }

    /// <summary>
    /// 获取店铺巡检问题列表
    /// </summary>
    public void GetShopProblemList()
    {
        string shopCode = _httpReuqest["shopCode"];
        string checkDate_str = _httpReuqest["checkDate"];
        DateTime? checkDate = null;
        if (!string.IsNullOrEmpty(checkDate_str))
        {
            checkDate = Convert.ToDateTime(checkDate_str);
        }
        var workOrderHandler = new WorkOrderHandler();
        var list = workOrderHandler.GetShopProblemList(shopCode, checkDate);
        Success(list);
    }

    /// <summary>
    /// 获取工单信息
    /// </summary>
    /// <param name="shopNames"></param>
    public void GetDetailByTidId()
    {
        int tid_id = 0;
        int.TryParse(_httpReuqest["tidId"], out tid_id);
        var workOrderHandler = new WorkOrderHandler();
        var detailFrom = workOrderHandler.GetDetailByTidId(tid_id);
        Success(detailFrom);
    }

    public void GetDetailByWId()
    {
        int wId = 0;
        int.TryParse(_httpReuqest["wId"], out wId);
        var workOrderHandler = new WorkOrderHandler();
        var detailFrom = workOrderHandler.GetDetailByWId(wId);
        Success(detailFrom);
    }

    /// <summary>
    /// 增加问题跟进实体
    /// </summary>
    public void SavaWorkOrder()
    {
        var savaJson = _httpReuqest["savaModel"];
        WordOrderVO.SavaModel result = null;
        if (savaJson != null)
        {
            var model = JSON.Deserialize<WordOrderVO.SavaModel>(savaJson);
            var workOrderHandler = new WorkOrderHandler();
            bool canOK = false;
            string msg = string.Empty;
            result = workOrderHandler.SavaModel(model, out msg, out canOK);
            if (!canOK)
            {
                Error(msg);
            }
            else
            {
                Success(result);
            }
        }

    }

    /// <summary>
    /// 删除工单
    /// </summary>
    /// <param name="shopNames"></param>
    public void DelectByWId()
    {
        int wId = 0;
        int.TryParse(_httpReuqest["wId"], out wId);
        var workOrderHandler = new WorkOrderHandler();
        string msg = string.Empty;
        bool result = workOrderHandler.DelectByWId(wId, out msg);
        if (result)
        {
            Success(result);
        }
        else
        {
            Error(msg);
        }

    }
}